/**
 * Disclaimer:
 * Copyright &copy 2005 - 2010 EMEA - All rights reserved. Privacy Policy
 * eof Disclaimer
 *
 * @author <A HREF="markos.fragkakis@trasys.gr">Markos Fragkakis</a> (created by)
 * @author  $Author: $ (last change by)
 * 
 * @version $Revision: $ (cvs revision)
 * @since 30 Απρ 2010 (creation date)
 * @revisionDate $Date: $
 */

package org.markos.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.markos.model.Company;
import org.markos.model.Product;
import org.markos.model.Version;

/**
 * TODO Place information about the class or interface here
 * 
 * @author fragkakm
 */
@Name("actionBean")
@Scope(ScopeType.SESSION)
public class ActionBean implements Serializable {

	private List<Company> companies = new ArrayList<Company>();

	@Begin
	public void init() {

		companies = new ArrayList<Company>();
		// add a company with products and with versions
		Company companyA = new Company();
		companyA.setName("Company A");
		for (int k = 0; k < 2; k++) {
			Product prod = new Product();
			prod.setName("Product A" + k);
			for (int m = 0; m < 2; m++) {
				Version version = new Version();
				version.setName("Version A" + m);
				prod.getVersions().add(version);
			}
			companyA.getProducts().add(prod);
		}
		// add a company with 2 products, second product has no versions
		Company companyB = new Company();
		companyB.setName("Company B");
		Product prodB0 = new Product();
		prodB0.setName("Product B0");
		for (int n = 0; n < 2; n++) {
			Version version = new Version();
			version.setName("Version B" + n);
			prodB0.getVersions().add(version);
		}
		companyB.getProducts().add(prodB0);
		Product prodB1 = new Product();
		prodB1.setName("Product B1");
		companyB.getProducts().add(prodB1);
		// add a company with no products
		Company companyC = new Company();
		companyC.setName("Company C");
		// Experiment on each one company individually by commenting out the
		// others
		companies.add(companyA);
		companies.add(companyB);
		companies.add(companyC);
	}

	/**
	 * @return the companies
	 */
	public List<Company> getCompanies() {

		init();
		return companies;
	}

	/**
	 * @param companies
	 *            the companies to set
	 */
	public void setCompanies(List<Company> companies) {

		this.companies = companies;
	}
}
